# -*- encoding: utf-8 -*-
"""
@File    : User_funnel.py
@Time    : 2020/3/26 1:36 下午
@Author  : david wang
@Email   : 3063737@qq.com
@Software: PyCharm
"""
# 导入插件
import pandas as pd
import numpy as np
from pandas import DataFrame
import setting
from pyecharts.globals import ThemeType
from pyecharts import options as opts
from pyecharts.charts import Funnel

# 定义文件路径
filename = setting.export_file+'User_funnel.html'
iopath = setting.resource_file+'User_loginout_his.xlsx'

# 读取xls文件
df_brower = pd.DataFrame(pd.read_excel(iopath, sheet_name='browser'))
df_x = df_brower['浏览器'].to_list()
# df_brower._stat_axis.values.tolist()  # 行名称
# df_brower.columns.values.tolist()  # 列名称

cols = df_brower.columns.values.tolist()
print (cols[0])

df_y = df_brower['合计'].to_list()
da0_brower = [list(i) for i  in zip(df_x,df_y)]    ## 用zip将对象迭代组合成元组，并用list罗列出来

c = (
    Funnel(init_opts=opts.InitOpts(theme=ThemeType.WHITE, height="800px", width="1500px"))
    .add(
        cols[0],
        da0_brower,
        label_opts=opts.LabelOpts(position="inside"),
    )
    .set_global_opts(title_opts=opts.TitleOpts(title="用户转换图", subtitle="XX用户转换"),
                     legend_opts=opts.LegendOpts(pos_left="right", orient="vertical"),
                     # legend_opts=opts.LegendOpts(pos_left="40%"),
                     )
    .render(filename)
)

import webbrowser
webbrowser.open_new_tab( 'file://'+filename)

